<template>
  <div style="text-align:left">
    <el-tree ref="tree" default-expand-all show-checkbox :default-checked-keys="tree.checkedKeys" node-key="key" :data="tree.data" accordion> </el-tree>
    <el-button type="primary" @click="handleSave">保存</el-button>
  </div>
</template>

<script>
  export default {
    name: 'RoleMenu',
    props: ['tree', 'role'],
    methods: {
      handleSave: function() {
        let keys = this.$refs.tree.getCheckedKeys(true)
        let body = { roleId: this.role.id, menuId: keys }
        this.$api.postMenu(body).then(res =>{
          this.$message({
            message: '保存成功',
            type: 'success'
          })
          this.$emit('success')
        })
      }
    },
    created: function() {
      console.log(this.tree)
    }
  }
</script>

<style>

</style>
